/******************************************************************************
 * Copyright 2023 The Apollo Authors. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *****************************************************************************/

#include "modules/canbus_vehicle/x3epro/protocol/vcu_brake_report_47.h"
#include "glog/logging.h"
#include "modules/drivers/canbus/common/byte.h"
#include "modules/drivers/canbus/common/canbus_consts.h"

namespace apollo {
namespace canbus {
namespace x3epro {

using ::apollo::drivers::canbus::Byte;

Vcubrakereport47::Vcubrakereport47() {}
const int32_t Vcubrakereport47::ID = 0x47;

void Vcubrakereport47::Parse(const std::uint8_t* bytes, int32_t length,
                         X3epro* chassis) const {
  chassis->mutable_vcu_brake_report_47()->set_brake_enable_resp(brake_enable_resp(bytes, length));
  chassis->mutable_vcu_brake_report_47()->set_control_mode_resp(control_mode_resp(bytes, length));
  chassis->mutable_vcu_brake_report_47()->set_vcu_real_brake_valid(vcu_real_brake_valid(bytes, length));
  chassis->mutable_vcu_brake_report_47()->set_vcu_real_brake(vcu_real_brake(bytes, length));
  chassis->mutable_vcu_brake_report_47()->set_aotoholdswitchstate(aotoholdswitchstate(bytes, length));
  chassis->mutable_vcu_brake_report_47()->set_aotoholdworkstatus(aotoholdworkstatus(bytes, length));
  chassis->mutable_vcu_brake_report_47()->set_vcu_real_parking_status(vcu_real_parking_status(bytes, length));
  chassis->mutable_vcu_brake_report_47()->set_vcu_real_parking_valid(vcu_real_parking_valid(bytes, length));
  chassis->mutable_vcu_brake_report_47()->set_rampauxiliaryindication(rampauxiliaryindication(bytes, length));
  chassis->mutable_vcu_brake_report_47()->set_vehicleslope(vehicleslope(bytes, length));
  chassis->mutable_vcu_brake_report_47()->set_vcu_ehb_braketype(vcu_ehb_braketype(bytes, length));
  chassis->mutable_vcu_brake_report_47()->set_vcu_brakerept_alivecounter(vcu_brakerept_alivecounter(bytes, length));
  chassis->mutable_vcu_brake_report_47()->set_vcu_brakerept_checksum(vcu_brakerept_checksum(bytes, length));
}

// config detail: {'bit': 0, 'enum': {0: 'BRAKE_ENABLE_RESP_INVALID', 1: 'BRAKE_ENABLE_RESP_VALID'}, 'is_signed_var': False, 'len': 1, 'name': 'brake_enable_resp', 'offset': 0.0, 'order': 'motorola', 'physical_range': '[0|0]', 'physical_unit': '', 'precision': 1.0, 'type': 'enum'}
Vcu_brake_report_47::Brake_enable_respType Vcubrakereport47::brake_enable_resp(const std::uint8_t* bytes, int32_t length) const {
  Byte t0(bytes + 0);
  int32_t x = t0.get_byte(0, 1);

  Vcu_brake_report_47::Brake_enable_respType ret =  static_cast<Vcu_brake_report_47::Brake_enable_respType>(x);
  return ret;
}

// config detail: {'bit': 6, 'enum': {0: 'CONTROL_MODE_RESP_STANDBY', 1: 'CONTROL_MODE_RESP_AUTO_DRIVE', 2: 'CONTROL_MODE_RESP_NET_DRIVE', 3: 'CONTROL_MODE_RESP_REMOTE_CONTROL', 4: 'CONTROL_MODE_RESP_EMERGENCY_BRAKE'}, 'is_signed_var': False, 'len': 3, 'name': 'control_mode_resp', 'offset': 0.0, 'order': 'motorola', 'physical_range': '[0|0]', 'physical_unit': 'bit', 'precision': 1.0, 'type': 'enum'}
Vcu_brake_report_47::Control_mode_respType Vcubrakereport47::control_mode_resp(const std::uint8_t* bytes, int32_t length) const {
  Byte t0(bytes + 0);
  int32_t x = t0.get_byte(4, 3);

  Vcu_brake_report_47::Control_mode_respType ret =  static_cast<Vcu_brake_report_47::Control_mode_respType>(x);
  return ret;
}

// config detail: {'bit': 7, 'enum': {0: 'VCU_REAL_BRAKE_INVALID', 1: 'VCU_REAL_BRAKE_VALID'}, 'is_signed_var': False, 'len': 1, 'name': 'vcu_real_brake_valid', 'offset': 0.0, 'order': 'motorola', 'physical_range': '[0|0]', 'physical_unit': '', 'precision': 1.0, 'type': 'enum'}
Vcu_brake_report_47::Vcu_real_brake_validType Vcubrakereport47::vcu_real_brake_valid(const std::uint8_t* bytes, int32_t length) const {
  Byte t0(bytes + 0);
  int32_t x = t0.get_byte(7, 1);

  Vcu_brake_report_47::Vcu_real_brake_validType ret =  static_cast<Vcu_brake_report_47::Vcu_real_brake_validType>(x);
  return ret;
}

// config detail: {'bit': 15, 'is_signed_var': False, 'len': 8, 'name': 'vcu_real_brake', 'offset': 0.0, 'order': 'motorola', 'physical_range': '[0|0]', 'physical_unit': '', 'precision': 1.0, 'type': 'int'}
int Vcubrakereport47::vcu_real_brake(const std::uint8_t* bytes, int32_t length) const {
  Byte t0(bytes + 1);
  int32_t x = t0.get_byte(0, 8);

  int ret = x;
  return ret;
}

// config detail: {'bit': 11, 'enum': {0: 'AOTOHOLDSWITCHSTATE_OFF', 1: 'AOTOHOLDSWITCHSTATE_ON'}, 'is_signed_var': False, 'len': 1, 'name': 'aotoholdswitchstate', 'offset': 0.0, 'order': 'motorola', 'physical_range': '[0|0]', 'physical_unit': 'bit', 'precision': 1.0, 'type': 'enum'}
Vcu_brake_report_47::AotoholdswitchstateType Vcubrakereport47::aotoholdswitchstate(const std::uint8_t* bytes, int32_t length) const {
  Byte t0(bytes + 1);
  int32_t x = t0.get_byte(3, 1);

  Vcu_brake_report_47::AotoholdswitchstateType ret =  static_cast<Vcu_brake_report_47::AotoholdswitchstateType>(x);
  return ret;
}

// config detail: {'bit': 12, 'enum': {0: 'AOTOHOLDWORKSTATUS_INACTIVE', 1: 'AOTOHOLDWORKSTATUS_ACTIVE'}, 'is_signed_var': False, 'len': 1, 'name': 'aotoholdworkstatus', 'offset': 0.0, 'order': 'motorola', 'physical_range': '[0|0]', 'physical_unit': 'bit', 'precision': 1.0, 'type': 'enum'}
Vcu_brake_report_47::AotoholdworkstatusType Vcubrakereport47::aotoholdworkstatus(const std::uint8_t* bytes, int32_t length) const {
  Byte t0(bytes + 1);
  int32_t x = t0.get_byte(4, 1);

  Vcu_brake_report_47::AotoholdworkstatusType ret =  static_cast<Vcu_brake_report_47::AotoholdworkstatusType>(x);
  return ret;
}

// config detail: {'bit': 18, 'enum': {0: 'VCU_REAL_PARKING_STATUS_EPB_RELEASED', 1: 'VCU_REAL_PARKING_STATUS_EPB_APPLIED', 2: 'VCU_REAL_PARKING_STATUS_EPB_RELEASING', 3: 'VCU_REAL_PARKING_STATUS_EPB_FAULT', 4: 'VCU_REAL_PARKING_STATUS_EPB_APPLYING'}, 'is_signed_var': False, 'len': 3, 'name': 'vcu_real_parking_status', 'offset': 0.0, 'order': 'motorola', 'physical_range': '[0|0]', 'physical_unit': '', 'precision': 1.0, 'type': 'enum'}
Vcu_brake_report_47::Vcu_real_parking_statusType Vcubrakereport47::vcu_real_parking_status(const std::uint8_t* bytes, int32_t length) const {
  Byte t0(bytes + 2);
  int32_t x = t0.get_byte(0, 3);

  Vcu_brake_report_47::Vcu_real_parking_statusType ret =  static_cast<Vcu_brake_report_47::Vcu_real_parking_statusType>(x);
  return ret;
}

// config detail: {'bit': 19, 'enum': {0: 'VCU_REAL_PARKING_INVALID', 1: 'VCU_REAL_PARKING_VALID'}, 'is_signed_var': False, 'len': 1, 'name': 'vcu_real_parking_valid', 'offset': 0.0, 'order': 'motorola', 'physical_range': '[0|0]', 'physical_unit': '', 'precision': 1.0, 'type': 'enum'}
Vcu_brake_report_47::Vcu_real_parking_validType Vcubrakereport47::vcu_real_parking_valid(const std::uint8_t* bytes, int32_t length) const {
  Byte t0(bytes + 2);
  int32_t x = t0.get_byte(3, 1);

  Vcu_brake_report_47::Vcu_real_parking_validType ret =  static_cast<Vcu_brake_report_47::Vcu_real_parking_validType>(x);
  return ret;
}

// config detail: {'bit': 20, 'enum': {0: 'RAMPAUXILIARYINDICATION_INACTIVE', 1: 'RAMPAUXILIARYINDICATION_ACTIVE'}, 'is_signed_var': False, 'len': 1, 'name': 'rampauxiliaryindication', 'offset': 0.0, 'order': 'motorola', 'physical_range': '[0|0]', 'physical_unit': '', 'precision': 1.0, 'type': 'enum'}
Vcu_brake_report_47::RampauxiliaryindicationType Vcubrakereport47::rampauxiliaryindication(const std::uint8_t* bytes, int32_t length) const {
  Byte t0(bytes + 2);
  int32_t x = t0.get_byte(4, 1);

  Vcu_brake_report_47::RampauxiliaryindicationType ret =  static_cast<Vcu_brake_report_47::RampauxiliaryindicationType>(x);
  return ret;
}

// config detail: {'bit': 31, 'is_signed_var': False, 'len': 8, 'name': 'vehicleslope', 'offset': 0.0, 'order': 'motorola', 'physical_range': '[0|0]', 'physical_unit': '°', 'precision': 0.1758125, 'type': 'double'}
double Vcubrakereport47::vehicleslope(const std::uint8_t* bytes, int32_t length) const {
  Byte t0(bytes + 3);
  int32_t x = t0.get_byte(0, 8);

  double ret = x * 0.175813;
  return ret;
}

// config detail: {'bit': 34, 'enum': {0: 'VCU_EHB_BRAKETYPE_NORMAL_BRAKE', 1: 'VCU_EHB_BRAKETYPE_BACKUP_REMOTE_BRAKE', 2: 'VCU_EHB_BRAKETYPE_EMERGENCY_BUTTON_BRAKE', 3: 'VCU_EHB_BRAKETYPE_ULTRASONIC_BRAKE', 4: 'VCU_EHB_BRAKETYPE_BUMPER_BRAKE'}, 'is_signed_var': False, 'len': 3, 'name': 'vcu_ehb_braketype', 'offset': 0.0, 'order': 'motorola', 'physical_range': '[0|0]', 'physical_unit': '', 'precision': 1.0, 'type': 'enum'}
Vcu_brake_report_47::Vcu_ehb_braketypeType Vcubrakereport47::vcu_ehb_braketype(const std::uint8_t* bytes, int32_t length) const {
  Byte t0(bytes + 4);
  int32_t x = t0.get_byte(0, 3);

  Vcu_brake_report_47::Vcu_ehb_braketypeType ret =  static_cast<Vcu_brake_report_47::Vcu_ehb_braketypeType>(x);
  return ret;
}

// config detail: {'bit': 51, 'is_signed_var': False, 'len': 4, 'name': 'vcu_brakerept_alivecounter', 'offset': 0.0, 'order': 'motorola', 'physical_range': '[0|0]', 'physical_unit': '', 'precision': 1.0, 'type': 'int'}
int Vcubrakereport47::vcu_brakerept_alivecounter(const std::uint8_t* bytes, int32_t length) const {
  Byte t0(bytes + 6);
  int32_t x = t0.get_byte(0, 4);

  int ret = x;
  return ret;
}

// config detail: {'bit': 63, 'is_signed_var': False, 'len': 8, 'name': 'vcu_brakerept_checksum', 'offset': 0.0, 'order': 'motorola', 'physical_range': '[0|0]', 'physical_unit': '', 'precision': 1.0, 'type': 'int'}
int Vcubrakereport47::vcu_brakerept_checksum(const std::uint8_t* bytes, int32_t length) const {
  Byte t0(bytes + 7);
  int32_t x = t0.get_byte(0, 8);

  int ret = x;
  return ret;
}
}  // namespace x3epro
}  // namespace canbus
}  // namespace apollo
